<template>
	<view class="book-search">
		<bsNavBar title='证书查询'></bsNavBar>
		<view class="form-box">
			<u-form :label-style='style' label-position='top' :error-type="errorType" :model="form" ref="uForm">
				<u-form-item label="姓名" prop="licensee">
					<u-input v-model="form.licensee" placeholder='请输入姓名' />
				</u-form-item>
				<u-form-item label="证书编号" prop="number">
					<u-input v-model="form.number" placeholder='请输入证书编号' />
				</u-form-item>
			</u-form>
		</view>
		<view class="btn-box">
			<u-button type='jz' @click="submit">立即查询</u-button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form: {
					licensee: '',
					number: '',
				},
				errorType: ['border-bottom', 'toast'],
				style: {
					color: '#303030',
					fontWeight: 'bold'
				},
				rules: {
					licensee: [{
						required: true,
						message: '请输入姓名',
						trigger: ['change', 'blur'],
					}],
					number: [{
						required: true,
						message: '请输入证书编号',
						trigger: ['change', 'blur'],
					}]
				},
				courseId: ''
			};
		},
		onLoad(e) {
			if (e.courseId) {
				this.courseId = e.courseId
			}
		},
		methods: {
			async submit() {

				this.$refs.uForm.validate(async valid => {
					if (valid) {
						this.form.courseId = this.courseId
						let res = await this.$u.api.findCertificate(this.form)
						let row = res ? JSON.stringify(res) : false
						console.log(row,'提交');
						uni.navigateTo({
							url: '/pages/onlineTrain/trainDetails/bookSearch/searchResult?row=' + row
						})
					} else {
						console.log('验证失败');
					}
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.book-search {
		.form-box {
			padding: 0 30rpx;
			padding-bottom: 200rpx;
		}

		.btn-box {
			background: #FFFFFF;
			box-shadow: 0 0 26px 0 rgba(18, 27, 83, 0.07);
			padding: 20rpx;
			position: fixed;
			bottom: 0;
			width: 100%;
		}
	}
</style>
